//
//  BandAplipayViewController.m
//  MJApp
//
//  Created by wangliang on 15/7/8.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "BandAplipayViewController.h"

@interface BandAplipayViewController ()
@property (weak, nonatomic) IBOutlet UITextField *alipayTextField;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UIButton *bandbtn;
@property (nonatomic,strong) NSDictionary *lastDic;

@end

@implementation BandAplipayViewController

- (instancetype)initWithDic:(NSDictionary *)dic {
    
    if (self = [super init]) {
        
        self.lastDic = dic;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self UI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)UI {
    
    self.title = self.lastDic[@"idStr"];
    
    self.view.backgroundColor = Color_Back_Black;
    self.alipayTextField.layer.cornerRadius = 2;
    self.alipayTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
    self.alipayTextField.leftViewMode = UITextFieldViewModeAlways;
    self.alipayTextField.font = [UIFont systemFontOfSize:17];
    self.nameTextField.layer.cornerRadius = 2;
    self.nameTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
    self.nameTextField.leftViewMode = UITextFieldViewModeAlways;
    self.nameTextField.font = [UIFont systemFontOfSize:17];
    
    self.bandbtn.layer.cornerRadius = CGRectGetHeight(self.bandbtn.frame) / 2;
}

- (void)postData {
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"user_id"] = [userInfoTool share].ID;
    dic[@"alipay"] = self.alipayTextField.text;
    
    [WLHttpRequestAfter userBindAlipayWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:resultDictionary[@"msg"]];
        if ([resultDictionary[@"status"] integerValue] == 1) {
            
            if ([self.lastDic[@"idStr"] isEqual:@"绑定支付宝"]) {
                
                NSInteger num = self.navigationController.viewControllers.count;
                [self.navigationController popToViewController:self.navigationController.viewControllers[num - 3] animated:YES];
            }else {
                
                [self.navigationController popViewControllerAnimated:YES];
            }
        }

    } andFailureBlock:^(NSError *resultError) {
        
    }];
}

- (IBAction)okButtonAction:(id)sender {
    
    [self postData];
}

@end
